<?php
include_once("game.php");
if(class_exists('SQL_Helper') != true)
{
   include_once("sql_helper.php");
}
class GameRepository
{
	function createGame($matchID, $gameNumber, $player1Score, $player2Score){
		SQL_Helper::executeNonQuery("INSERT INTO `game` (`matchID`, `gameNumber`, `player1Score`, `player2Score`) VALUES(?,?,?,?)",$matchID, $gameNumber, $player1Score, $player2Score);
	}
	
	function readGame($matchID, $gameNumber){
		return SQL_Helper::executeQuerySingle("Select * from `game` where `matchID` = ? and `gameNumber` = ?", $matchID, $gameNumber);
	}
	
	function updateGame($matchID, $gameNumber, $player1Score, $player2Score){
		SQL_Helper::executeNonQuery("Update `game` set `player1Score`=?, `player2Score`=? where `matchID` = ? and `gameNumber`=?",$player1Score, $player2Score, $matchID, $gameNumber);
	}
	
	function deleteGame($matchID, $gameNumber){
		SQL_Helper::executeNonQuery("delete from `game` where `matchID` = ? and `gameNumber`=?", $matchID, $gameNumber);
	}
	
	function map($row){
		$class= "Game";
		return SQL_Helper::sql_map($row,$class);
	}
	function maps($rows){
		$class= "Game";
		return SQL_Helper::sql_maps($rows,$class);
	}

	function getGamesByMatchID($matchID){
		return SQL_Helper::executeQuery("Select * from `game` where `matchID` = ?", $matchID);
	}
	
	function checkGame($matchID, $gameNumber){
		return SQL_Helper::executeQuery("Select * from `game` where `matchID` = ? and `gameNumber` = ?", $matchID, $gameNumber);
	}
}
?>